package com.enn.demo.biz.service.impl.application.impl;

import com.enn.demo.biz.service.impl.application.SysPersonApplicationService;
import com.enn.demo.biz.service.impl.application.assembler.PersonDTOAssembler;
import com.enn.demo.biz.service.impl.application.command.PersonCommand;
import com.enn.demo.core.service.impl.domain.model.person.Person;
import com.enn.demo.core.service.impl.domain.model.person.PersonId;
import com.enn.demo.core.service.impl.domain.model.person.PersonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 用户 服务实现类
 * </p>
 *
 * @author kll
 * @since 2021-05-14
 */
@Service
public class SysPersonApplicationServiceImpl implements SysPersonApplicationService {

    @Autowired
    private PersonRepository personRepository;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void savePerson(PersonCommand personCommand) {
        personRepository.store(PersonDTOAssembler.toPerson(personCommand));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deletePerson(String id) {
        personRepository.remove(new PersonId(id));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void disablePerson(String id) {
        Person person = personRepository.find(new PersonId(id));
        person.disable();
        personRepository.store(person);
    }
}
